import matplotlib.patches as patches
from matplotlib import pyplot as plt

# 创建画布
fig, ax = plt.subplots(figsize=(10, 6))

# 无人机图标（用矩形代替）
uav = patches.FancyBboxPatch((0.05, 0.55), 0.15, 0.15, boxstyle="round,pad=0.02", fc="#FFD966", ec="black", lw=1.5)
ax.add_patch(uav)
ax.text(0.125, 0.625, "无人机\n(UAV)", ha="center", va="center", fontsize=11, weight="bold")

# 地面用户
user = patches.FancyBboxPatch((0.05, 0.15), 0.15, 0.15, boxstyle="round,pad=0.02", fc="#9FC5E8", ec="black", lw=1.5)
ax.add_patch(user)
ax.text(0.125, 0.225, "地面用户", ha="center", va="center", fontsize=11, weight="bold")

# MEC服务器
mec = patches.FancyBboxPatch((0.8, 0.55), 0.15, 0.15, boxstyle="round,pad=0.02", fc="#B6D7A8", ec="black", lw=1.5)
ax.add_patch(mec)
ax.text(0.875, 0.625, "MEC服务器", ha="center", va="center", fontsize=11, weight="bold")

# 控制中心/充电站
charge = patches.FancyBboxPatch((0.8, 0.15), 0.15, 0.15, boxstyle="round,pad=0.02", fc="#F4CCCC", ec="black", lw=1.5)
ax.add_patch(charge)
ax.text(0.875, 0.225, "充电/补给站", ha="center", va="center", fontsize=11, weight="bold")

# 箭头连接（任务卸载/数据链路）
ax.annotate("", xy=(0.2, 0.625), xytext=(0.8, 0.625), arrowprops=dict(arrowstyle="->", lw=1.5, color="black"))
ax.text(0.5, 0.65, "任务卸载/结果返回", ha="center", fontsize=10)

# UAV 与用户通信
ax.annotate("", xy=(0.125, 0.55), xytext=(0.125, 0.3), arrowprops=dict(arrowstyle="->", lw=1.5, color="black"))
ax.text(0.17, 0.425, "无线链路", rotation=90, va="center", fontsize=10)

# UAV 飞行到补给站
ax.annotate("", xy=(0.2, 0.55), xytext=(0.8, 0.3), arrowprops=dict(arrowstyle="->", lw=1.5, linestyle="--", color="gray"))
ax.text(0.55, 0.45, "返航路径", fontsize=10, color="gray")

# 能量管理模块
energy_box = patches.FancyBboxPatch((0.4, 0.15), 0.2, 0.2, boxstyle="round,pad=0.02", fc="#FFF2CC", ec="black", lw=1.5)
ax.add_patch(energy_box)
ax.text(0.5, 0.25, "能量管理与\n任务调度模块", ha="center", va="center", fontsize=11, weight="bold")

# 从UAV到能量管理模块
ax.annotate("", xy=(0.2, 0.55), xytext=(0.4, 0.25), arrowprops=dict(arrowstyle="->", lw=1.5, color="black"))
ax.text(0.32, 0.4, "能量状态\nE_t", ha="center", fontsize=9)

# 从能量管理模块到 UAV 控制
ax.annotate("", xy=(0.6, 0.25), xytext=(0.2, 0.625), arrowprops=dict(arrowstyle="->", lw=1.5, color="black"))
ax.text(0.45, 0.45, "飞行速度/功率/\n计算频率", ha="center", fontsize=9)

# 坐标轴隐藏
ax.axis("off")

plt.title("基于能量约束的无人机飞行与计算资源动态调度优化框架", fontsize=14, weight="bold")
plt.tight_layout()
plt.show()
